package com.cgsd.heyu.ui.task.adapter;

import android.text.Html;
import android.text.TextUtils;

import com.cgsd.heyu.R;
import com.cgsd.heyu.common.AvatarManger;
import com.cgsd.heyu.ui.task.vo.MyTaskVo;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

/**
 * Author: sky on 2021/3/1 17:06
 * Email: xcode126@126.com
 * Desc: 我的任务-我的报名
 */
public class MyBookAdapter extends BaseQuickAdapter<MyTaskVo.TasklistBean, BaseViewHolder> {

    public MyBookAdapter() {
        super(R.layout.item_my_book);
    }

    @Override
    protected void convert(BaseViewHolder helper, MyTaskVo.TasklistBean item) {
        AvatarManger.setAvatar(mContext, item.userImg, helper.getView(R.id.iv_bg));
        helper.setText(R.id.tv_name, item.title);
        helper.setText(R.id.tv_v, String.format("%1$s%2$.2f%3$s", "V：", item.price, mContext.getString(R.string.a_unit_yuan)));//VIP价格
        helper.setText(R.id.tv_reward, String.format("%1$s%2$.2f%3$s", mContext.getString(R.string.a_reward_), item.price1, mContext.getString(R.string.a_unit_yuan)));//普通价格
        helper.setText(R.id.tv_commit, Html.fromHtml(String.format("%1$s<font color='#666666'>%2$s%3$s</font>", mContext.getString(R.string.a_commit_), item.finish, mContext.getString(R.string.a_unit_hour))));
        helper.setText(R.id.tv_task_progress, Html.fromHtml(String.format("%1$s<font color='#33B9CC'>%2$s</font>", mContext.getString(R.string.a_task_progress_), item.statetext)));

        helper.setText(R.id.tv_look, mContext.getString(R.string.a_commit));
        helper.setGone(R.id.tv_look,isShowCommit(item.state));

        helper.setText(R.id.tv_reason,String.format("%1$s%2$s","驳回原因：",item.reason));
        helper.setGone(R.id.tv_reason,TextUtils.equals(item.state,"3"));
    }

    /**
     * 提交按钮是否显示，除待提交和驳回右侧显示提交外，均不显示
     * @param state
     * @return
     */
    private boolean isShowCommit(String state){
        if (TextUtils.isEmpty(state)){
            return false;
        }
        if (TextUtils.equals(state,"0")||TextUtils.equals(state,"3")){
            return true;
        }
        return false;
    }
}
